package com.supply.dl.activity.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.View;

import com.supply.dl.activity.BaseActivity;
import com.supply.dl.widget.LoadTipFailedLayout;

import butterknife.ButterKnife;

/**
 * <p>Fragment(项目中的所有Fragment都继承自此类)</p>
 * <p>time 2014/10/27</p>
 *
 * @version CmgeForum 1.0.0
 */
public abstract class BaseFragment extends Fragment {
    public LoadTipFailedLayout loadTipFailedLayout;
    protected View viewRoot;

    protected BaseActivity mActivity;

    private boolean isVisibleToUser;

    protected Handler mHandler = new Handler();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // ButterKnife.bind(mActivity);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mActivity = (BaseActivity) activity;
    }

    public void onViewCreated(View view, Bundle savedInstanceState) {
        this.viewRoot = view;
        super.onViewCreated(view, savedInstanceState);
    }

    public View findViewById(int id) {
        return viewRoot.findViewById(id);
    }

    @Override
    public void startActivity(Intent intent) {
        super.startActivity(intent);
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        this.isVisibleToUser = isVisibleToUser;
        super.setUserVisibleHint(isVisibleToUser);
    }

    /**
     * onNewBundle(Bundle data)
     *
     * @param data
     */
    public void onNewBundle(Bundle data) {
    }

    public boolean isVisibleToUser() {
        return isVisibleToUser;
    }

    /**
     * .
     * 跳转页面,并且保留当前页面
     *
     * @param cls
     */
    public void jumpActivity(Activity activity, Class<? extends BaseActivity> cls) {
        Intent intent = new Intent(activity, cls);
        startActivity(intent);
    }

    /**
     * 携带数据跳转页面,并且保留当前页面
     *
     * @param cls
     * @param bundle
     */
    public void jumpActivity(Activity activity, Class<? extends BaseActivity> cls, Bundle bundle) {


        Intent intent = new Intent(activity, cls);
        intent.putExtras(bundle);
        startActivity(intent);
    }

}
